DECLARE @LogDatetime datetime,
	@source		varchar(100),
	@Message	varchar(1000),
	@form		varchar(4000),
	@querystring	varchar(2000),
	@targetsite	varchar(300),
	@stacktrace	varchar(5000),
	@referrer	varchar(250)

DECLARE ERRORS CURSOR FOR
(
SELECT TOP 5
	[LogDateTime], 
	[Source], 
	[Message], 
	[Form], 
	[QueryString], 
	[TargetSite], 
	[StackTrace], 
	[Referrer] 
FROM 
	[dbo].[ExceptionLog]
)
ORDER BY
	LogDateTime DESC

OPEN ERRORS

FETCH NEXT FROM ERRORS INTO
	@LogDatetime,
	@source,
	@Message,
	@form,
	@querystring,
	@targetsite,
	@stacktrace,
	@referrer


WHILE @@FETCH_STATUS = 0
BEGIN
	--PROCESS THE CURRENT CASE
	PRINT ('Date/Time: '+CONVERT(varchar, @logdatetime))
	PRINT ('Source: '+@source)
	PRINT ('Message: '+@message)
	PRINT ('Form Values: '+@form)
	PRINT ('Query String: '+@querystring)
	PRINT ('TargetSite: '+@targetsite)
	PRINT ('Stacktrace: '+@stacktrace)
	PRINT ('Referrer: '+@referrer)

	PRINT ('')


	FETCH NEXT FROM ERRORS INTO
		@LogDatetime,
		@source,
		@Message,
		@form,
		@querystring,
		@targetsite,
		@stacktrace,
		@referrer
END

CLOSE ERRORS
DEALLOCATE ERRORS


